home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 29 / pascal / txttorec.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1985-11-19  |  3.4 KB  |  73 lines

  1. PROGRAM MakeKbd;
  2. TYPE
  3. { This program is an example of how to read a TEXT File and Write out a }
  4. {(file consisting of Pascal "Records"}
  5.         STR9 = STRING[9];   {Define a String Type that is common to all}
  6.         KeyRec = RECORD     {Define a record of 5 integers and a 9 byte string}
  7.                 KeyCode:INTEGER;
  8.                 KLabel:STR9;
  9.                 KeyH:INTEGER;
  10.                 KeyW:INTEGER;
  11.                 KeyX:INTEGER;
  12.                 KeyY:INTEGER;
  13.                 END;
  14.         InFileT = File OF TEXT;{Define a Text File Type}
  15.         OutFileT = FILE OF KeyRec;{ Define a "Record File Type"}
  16. VAR
  17.         {Declare are file variables}
  18.         Infile: InfileT; OutFile:OutFileT;
  19.         {Define a Boolean for EOF Detection}
  20.         EOF_Flag: BOOLEAN;
  21.         IC,OC,I: INTEGER;{IC::= Input Counter, OC::= Output Counter}
  22.         INCode,InH,InW,InX,InY:INTEGER; {Input Integers}
  23.         InLabel:STR9; {Input String}
  24.         KR: KeyRec;  {Output Record}
  25. PROCEDURE OpenFiles;
  26.         BEGIN
  27.         OC:=0;   {Set input/output counters to 0}
  28.         IC:=0;
  29.         RESET(InFile,'A:\Keyboard.TXT'); {Open the Text file for input}
  30.         REWRITE(OutFile,'A:\Keyboard.REC');{open the output "record file"}
  31.         {note: the above 2 files n file for input}
  32.         REWRITE(OutFile,'A:\Keyboard.REC');{open the output "record file"}
  33.         {note: the above 2 files names are hard coded they don't have to be}
  34.         END;
  35. PROCEDURE DoFiles;
  36.         BEGIN
  37.         READ(InFile,InCode);    {Read first integer off a line of Text}
  38.         READ(InFile,InH);       {Read 2nd integer off a line of text}
  39.         READ(InFile,INW);       {Read 3rd integer off the text line}
  40.         READ(InFile,InX);       {Read 4th integer off the text line}
  41.         READ(InFile,InY);       {Read 5th Integer off the text line}
  42.         READLN(InFile,InLabel); {Read the String and position at the}
  43.                                 {Start of the next line}
  44.                                 {note: numeric variables are delimited}
  45.                                 {by a Space}
  46.         IC:=IC+1;               {Add 1 to in record count}
  47.         Eof_flag := EOF(INFile); {Test for End of File}
  48.                                  {Even if we got an EOF write the last record}
  49.                                  {because the eof was caused by a lack of a}
  50.                                  {next text line while doing the READLN}
  51.         KR.KeyCode:=InCode;  {move input variable contents to output}
  52.         KR.KLabel:= InLabel; {record}
  53.         KR.KeyW:=InW;
  54.         KR.KeyH:=InH;
  55.         KR.KeyX:=InX;
  56.         KR.KeyY:=Iny;
  57.         OutFile^ := KR; {Store the output record in file buffer}
  58.         Put(OutFile);   {Write the record}
  59.         OC:=OC + 1;     {increment output record count}
  60.         IF EOF_Flag THEN  {at end of file write summary}
  61.                           {note this appears on the top of screen when this }
  62.                           {program runs under Gem}
  63.                 BEGIN
  64.                 Writeln(IC:4, ' Records read  ',OC:4,' Records written');
  65.                 Close(InFile);  {you have to close or tos will run out of}
  66.                 Close(OutFile); {file handles}
  67.                 END;
  68.         END;
  69.         BEGIN {Main}    {look ma know Gem}
  70.         Openfiles;
  71.         WHILE (EOF_Flag = False) DO DoFiles;
  72.    END.
  73. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;